package com.example.studentmanager.Service.impl;

import com.example.studentmanager.Dao.BaseDao;
import com.example.studentmanager.Dao.HomeDao;
import com.example.studentmanager.Pojo.Home;
import com.example.studentmanager.Service.HomeService;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class homeimpl implements HomeService {
    @Override
    public List<Home> Qhome() {
        HomeDao h=new HomeDao();
        List<Home> list=new ArrayList<>();
        try {
         ResultSet rs= h.Queryall();
         while (rs.next()){
             Home hh=new Home();
             hh.setHomeid(rs.getString("homeid"));
             hh.setBedid(rs.getInt("bedid"));
             hh.setPrice(rs.getString("price"));
             list.add(hh);
         }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return list;
    }

    @Override
    public int InsertHome(Home home) {
        BaseDao baseDao=new BaseDao();
        HomeDao h=new HomeDao();
   String sql=     h.InsertIntohome();
        int i = baseDao.InsertHome(sql, home);
        return i;
    }
}
